import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      resolvers: [ElementPlusResolver()],
      eslintrc: {
          enabled: true
      }
    }),
    Components({
        directoryAsNamespace: true,
        resolvers: [ElementPlusResolver()]
    }),
    createStyleImportPlugin({
        resolves: [ElementPlusResolve()]
    }),
    createSvgIconsPlugin({
        // 配置路劲在你的src里的svg存放文件
        iconDirs: [fileURLToPath(new URL('./src/assets/icons', import.meta.url))],
        symbolId: 'local-icon-[dir]-[name]'
    }),
    vueSetupExtend(), 
  ],
  // server: {			
  //   //  host: '192.168.0.105',	// 本机的局域网IP
  //   //  port: '5174',  // 端口号，一般情况下为8080 
  //   proxy: {
  //     '/': {
  //       target: 'http://39.105.135.116:8889',
  //       changeOrigin: true,
  //       // rewrite: (path) => path.replace(/^\/api/, '')
  //     }
  //   }
  // }, 
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    assetsDir: 'assets',
    // rollupOptions: {
    //     manualChunks(id) {
    //         if (id.includes('node_modules')) {
    //             return id.toString().split('node_modules/')[1].split('/')[0].toString()
    //         }
    //     }
    // }
  }
})
